﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Bitmap b;     
        Bitmap newB;  
        
      
        
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            Int32[] argb = new Int32[4];
            Int32 br = trackBar1.Value;  
            
            for (Int32 i = 0; i < b.Width; i++) 
                for (Int32 j = 0; j < b.Height; j++) 
                {
                    
                    argb[0] = b.GetPixel(i, j).A;
                    argb[1] = b.GetPixel(i, j).R;
                    argb[2] = b.GetPixel(i, j).G;
                    argb[3] = b.GetPixel(i, j).B;
                  for (Int32 n = 1; n < 4; n++)
            {
                if (argb[n] + br >= 0 && argb[n] + br <= 255)  
                    argb[n] += br;                            
                else if (argb[n] + br < 0)
                    argb[n] = 0;                              
                else
                    argb[n] = 255;                           
            }
                    newB.SetPixel(i, j, Color.FromArgb(argb[0], argb[1], argb[2], argb[3]));

                }
            

            pictureBox1.Image = newB; 
        }

        private void открытьToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
openFileDialog1.Filter = "Файлы изображений (bmp,jpg,gif,png)|*.bmp;*.png;*.jpg;*.gif"; 
            if (DialogResult.OK == openFileDialog1.ShowDialog())
            {
                b = new Bitmap(openFileDialog1.FileName);
                pictureBox1.Image = b;                   
                newB = new Bitmap(b);                     
            }
        }

        private void сохронитьToolStripMenuItem_Click(object sender, EventArgs e)
        {

            saveFileDialog1.Filter = "Точечный рисунок|*.bmp;|PNG формат|*.png;|JPEG файл |*.jpg;|GiF файл|*.gif"; 
            if (DialogResult.OK == saveFileDialog1.ShowDialog())
                newB.Save(saveFileDialog1.FileName); 
        }

        private void button1_Click(object sender, EventArgs e)
        {
        
                    
        }
    }
}
